﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using OpenLS.UI;

namespace OpenLS.Spreadsheet.UI.Internals
{
    public class SkinManager
    {
        public static void SetSkin (ResourceDictionary dictionary)
        {
            Application app = Application.Current;
            List<ResourceDictionary> toRemove =
                app.Resources.MergedDictionaries.Where(
                    d => d.GetType().GetCustomAttributes(typeof(SpreadsheetSkinAttribute), true).Length > 0).ToList();
            foreach (var d in toRemove)
                Application.Current.Resources.MergedDictionaries.Remove(d);
            app.Resources.MergedDictionaries.Add(dictionary);

        }
    }
    public class OptionsViewModel
    {
        public ICommand SetSkin { get { return new DelegateCommand(OnSetSkin); } }

        private void OnSetSkin(object obj)
        {
            ResourceDictionary dictionary = (ResourceDictionary) obj;
            SkinManager.SetSkin(dictionary);
        }
        public IEnumerable<ResourceDictionary> Skins
        {
            get
            {
                yield return new Spreadsheet2007BlueSkin();
                yield return new Spreadsheet2010BlackSkin();
                yield return new Spreadsheet2010SilverSkin();
            }
        }
    }
}
